package com.hison.courseselectionsystem.controller;

import com.hison.courseselectionsystem.domain.Course;
import com.hison.courseselectionsystem.service.CourseService;
import com.hison.courseselectionsystem.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName: CourseController
 * @Descripiton: TODO
 * @Author: 小郑
 * @Date： 2023/11/17 14:08
 * @Version：1.8
 **/
@RequestMapping("/course")
@RestController
@Api(value = "课程接口",description = "添加教授课程，删除教授课程，修改教授课程,查看选了自己课程的学生")
public class CourseController {

    @Resource
    private CourseService courseService;

    /**
     * 添加课程
     * @param course
     * @return {@link Result}
     */
    @ApiOperation(value = "添加课程",notes = "添加课程接口",produces = "application/json")
    @PostMapping("/add")
    public Result add(@RequestBody Course course){
        return  courseService.add(course);
    }

    /**
     * 删除课程
     * @param id
     * @return {@link Result}
     */
    @ApiOperation(value = "删除课程",notes = "删除课程接口",produces = "application/json")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return courseService.delete(id);
    }

    /**
     * 修改课程
     * @param course
     * @return {@link Result}
     */
    @ApiOperation(value = "修改课程", notes = "修改课程信息接口",produces = "application/json")
    @PutMapping("/update")
    public Result update(@RequestBody Course course) {
       return courseService.update(course);
    }

    /**
     * 根据名称查找课程
     * @param id
     * @return {@link Result}
     */
    @ApiOperation(value = "根据id查找课程",notes = "根据id查找 课程接口",produces = "application/json")
    @GetMapping("/findbyid/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return courseService.findById(id);
    }

    @ApiOperation(value = "根据名称查找课程",notes = "根据名称查找课程",produces = "application/json")
    @GetMapping("/findbyname/{name}")
    public Result findByName(@PathVariable("name") String name) {
        return courseService.findByName(name);
    }


}